package tt.com.cremationmanager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tt.com.common.model.Cremate;
import tt.com.common.util.CommonResult;
import tt.com.cremationmanager.service.CrematesService;
import tt.com.cremationmanager.vo.CrematesVo;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "cre/fire")
public class CrematesController {

    @Autowired
    private CrematesService service;

    @PostMapping(value = "show/cre")
    public ResponseEntity showCremateMessage(@RequestBody CrematesVo vo, HttpServletRequest request){
        CommonResult result = service.showCremateMessage(vo.getStatus(),vo.getPageUtil());
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @PostMapping(value = "select/cre")
    public ResponseEntity selectCremateMessage(@RequestBody CrematesVo vo, HttpServletRequest request){
        CommonResult result = service.selectCremateMessage(vo.getCremate(),vo.getPageUtil());
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @PostMapping(value = "update/cre")
    public ResponseEntity updateCremateMessage(@RequestBody Cremate cremate, HttpServletRequest request){
        CommonResult result = service.updateCremateMessage(cremate);
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @PostMapping(value = "insert/cre")
    public ResponseEntity insertCremateMessage(@RequestBody Cremate cremate, HttpServletRequest request){
        CommonResult result = service.insertCremateMessage(cremate);
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @PostMapping(value = "delete/cre")
    public ResponseEntity deleteCremateMessage(@RequestBody Cremate cremate, HttpServletRequest request){
        CommonResult result = service.deleteCremateMessage(cremate);
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @PostMapping(value = "ref/cre")
    public ResponseEntity refreshCremateMessage(@RequestBody CrematesVo vo, HttpServletRequest request){
        CommonResult result = service.refreshCremateMessage(vo.getPageUtil());
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @GetMapping(value = "select/freeCre")
    public ResponseEntity selectFreeCreateStove(HttpServletRequest request){
        CommonResult result = service.selectFreeCreateStove();
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @PostMapping(value = "start/cre")
    public ResponseEntity startCreate(@RequestBody Cremate cremate, HttpServletRequest request){
        CommonResult result = service.startCreate(cremate);
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @PostMapping(value = "stop/cre")
    public ResponseEntity stopCreate(@RequestBody Cremate cremate, HttpServletRequest request){
        CommonResult result = service.stopCreate(cremate);
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }

    @PostMapping(value = "con/bone")
    public ResponseEntity convergenceBone(@RequestBody Cremate cremate, HttpServletRequest request){
        CommonResult result = service.convergenceBone(cremate);
        return new ResponseEntity(result, HttpStatus.valueOf(result.getStatus()));
    }
}
